package com.jiayang.hhotel.util;

import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.TranslateAnimation;

/**
 * Created by Administrator on 2017/5/22 0022.
 * 动画工具类
 */

public class FlashUtil {

    public static final int TAG_ROTATE_ANIMATION=10000;//旋转动画tag

    private static Animation rotateAnimation;

    /**
     * 旋转动画
     */
    public static void rotateAnim(View view){
        if(rotateAnimation==null){
            rotateAnimation= new RotateAnimation(0,359,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
        }
        LinearInterpolator lin=new LinearInterpolator();
        rotateAnimation.setDuration(300);
        rotateAnimation.setRepeatCount(-1);
        rotateAnimation.setInterpolator(lin);
        view.startAnimation(rotateAnimation);

    }

    /**
     * 向上平移自身高度
     * @param view view
     */
    public static void TranslateUPAnim(View view){
        AnimationSet set = new AnimationSet(true);
        TranslateAnimation translate = new TranslateAnimation(
                Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
                Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, -1.5f);
        set.addAnimation(translate);
        translate.setDuration(300);
        translate.setFillAfter(true);
        set.setFillAfter(true);
        view.startAnimation(set);
    }

    /**
     * 从自身高度上边的位置平移至当前位置
     * @param view view
     */
    public static void TranslateDownAnim(View view){
        AnimationSet set = new AnimationSet(true);
        TranslateAnimation translate = new TranslateAnimation(
                Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
                Animation.RELATIVE_TO_SELF, -1.5f, Animation.RELATIVE_TO_SELF, 0);
        set.addAnimation(translate);
        translate.setDuration(300);
        translate.setFillAfter(true);
        set.setFillAfter(true);
        view.startAnimation(set);
    }

    /**
     * 清除动画
     */
    public static void cleanAnim(View view){
                if(rotateAnimation!=null){
                    view.clearAnimation();
                }
    }
}
